// pages/download/download.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    downloadList: [],
    contact_phone:'',
    showActionTip:false,
    downloadListMore: {page:1}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   //客服电话
    core.get({url:'xilujob.common/getphone',data:{},success:(ret)=>{
      this.setData({contact_phone:ret.data.phone});
    }});
    this.fetch();
  },
  fetch() {
    util.fetch(this, 'xilujob.resume/download_list', {}, 'downloadListMore','downloadList','data');
  },
  bindDownload(event) {
    let index = event.currentTarget.dataset.index;
    let download = this.data.downloadList[index];
    core.post({url:'xilujob.resume/get_contact',data:{resume_id:download.resume_id,user_id:download.user_id},success:ret=>{
      core.post({
        url: 'xilujob.resume/download',data:{id:download.resume_id},
        success: ret => {
          let url = ret.data.jpg_path;
          wx.previewImage({
            urls: [url], current: url,
          });
        }
      });
    },fail:ret=>{
      if(ret.code==-1) {
        this.setData({actionTipMsg: ret.msg});
        this.actionTip();
        return false;
      }
    }});

  },
  onShareAppMessage(res) {
    let resume = this.data.downloadList[res.target.dataset.index].resume;
    let title = '西陆 - 简历(' + resume.personal.realname + ')';
    return {
      title: title,
      path: '/pages/talent_info_detail/talent_info_detail?id='+resume.id,
    };
  },

  actionTip() {
    this.setData({showActionTip: !this.data.showActionTip});
  },
  actionTipTwo(e) {
   wx.makePhoneCall({phoneNumber: e.currentTarget.dataset.phone});
   this.setData({showActionTip: !this.data.showActionTip});
 }

});
